
#load data
data_BES_4 <- read.dta("Study 1/Original Data/BES2015_W4_v3.9.dta")
data_BES_6 <- read.dta("Study 1/Original Data/BES2015_W6_v3.9.dta")
data_BES_7 <- read.dta("Study 1/Original Data/BES2015_W7_v2.2-1.dta")

#select relevant variables
data_BES_4 <- data_BES_4[c("id", "immigCultural", "immigEcon", "immigrantsWelfareState")]
data_BES_6 <- data_BES_6[c("id", "country", "personality_openness", "personality_conscientiousness", "personality_extraversion", "personality_agreeableness", "personality_neuroticism", "gender", "Age", "likeBNP", "likeLD", "likeGrn", "generalElectionVote", "leftRight", "efficacyPolCare", "redistSelf", "profile_gross_household", "edlevel", "likeCon", "likeLab", "likeUKIP", "likeLD", "likeGrn", "likeBNP", "genElecTurnoutRetro")]
data_BES_7 <- data_BES_7[c("id", "auth1", "auth2", "auth3", "auth4")]

#merge data
data_BES<-merge(data_BES_6, data_BES_7, by="id", all=TRUE)
data_BES<-merge(data_BES, data_BES_4, by="id", all=TRUE)

#select variables for "analysis dataset"
data_BES <- data_BES[,which(colnames(data_BES)%in%c("id", "immigCultural", "immigEcon", "immigrantsWelfareState", "country", "personality_openness", "personality_conscientiousness", "personality_extraversion", "personality_agreeableness", "personality_neuroticism", "gender", "Age", "likeBNP", "likeLD", "likeGrn", "generalElectionVote", "leftRight", "efficacyPolCare", "redistSelf", "profile_gross_household", "edlevel", "likeCon", "likeLab", "likeUKIP", "likeLD", "likeGrn", "likeBNP", "genElecTurnoutRetro", "auth1", "auth2", "auth3", "auth4"))]

#save data
save(data_BES, file="Study 1/Original Data (shareable)/Study1_UK_BES_analysisdata.Rdata")